import { handleActions } from 'redux-actions'

export default handleActions({
  'request upload pic': (state, { payload }) => {
		return {
			...state,
			uploadInfo: payload,
			// init
			uploadStatus: 0
		}
  },

  'upload file': (state, { payload }) => {
    const { res, _uuid, meta } = payload
    return {
      ...state,
      uploadStatus: res.status >= 200 && res.status < 300,
      waitCreated: [
        ...state.waitCreated,
				{
					_uuid,
					meta
				}
      ],
      _uuid
    }
  },

  'done upload file': (state, { payload }) => {
    const { _uuid } = payload
    return {
      ...state,
      waitCreated: state.waitCreated.filter(item => item != _uuid)
    }
  }
}, {
  waitCreated: []
})
